﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace SLBehaviourSystem
{
    public class BehaviourComponent:MonoBehaviour
    {
        public IBehaviourAgent Agent;
        protected Action<BehaviourNodeState> OnExcuted;
        protected BehaviourNodeBase node;
        public void Init(IBehaviourAgent agent)
        {
            Agent = agent;
            enabled = false;
            OnInit();
        }

        public void BindNode(BehaviourNodeBase node)
        {
            this.node = node;
            OnBindNode();
        }

        protected virtual void OnBindNode()
        {
            
        }

        protected virtual void OnInit()
        {

        }

        public virtual BehaviourNodeState Excute()
        {
            return BehaviourNodeState.Success;
        }

        public virtual void ExcuteAsync(Action<BehaviourNodeState> onExcuteCompleted)
        {
            enabled = true;
            OnExcuted = onExcuteCompleted;
        }

        public virtual void Reset()
        {

        }
    }
}
